package cn.lny.org.service.impl;

import cn.lny.basic.PageList;
import cn.lny.org.domain.Department;
import cn.lny.org.mapper.DepartmentMapper;
import cn.lny.org.query.DepartmentQuery;
import cn.lny.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceimpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    @Transactional
    public void add(Department department) {
        departmentMapper.add(department);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    public Department queryOne(Long id) {
        return departmentMapper.findOne(id);
    }

    @Override
    public List<Department> queryAll() {
        return departmentMapper.findAll();
    }

    @Override
    public PageList<Department> queryDate(DepartmentQuery departmentQuery) {
        Long aLong = departmentMapper.queryCount();
        List<Department> departments = departmentMapper.queryDate(departmentQuery);

        return new PageList<>(aLong,departments);
    }
}
